
def solution1(m):
    a = 0
    for x in range(m+1):
        if '4' in str(x):
            a +=1
    return m-a

def solution2(n):
    m = 0
    more = 0
    while m < n:
        # 不知道4会出现在个、十、百、千、万哪儿个位置
        if '4' in str(m):
            this_m = int(str(m).replace("4", "5"))
            if this_m <= n:
                more += this_m - m
                m = this_m
            else:
                break
        else:
            m += 1
    return n-more


def compare(n):
    i = 0
    while i <= n:
        # if '4' in str(i):
        #     i += 1
        #     continue
        s1 = solution1(i)
        s2 = solution2(i)
        if s1 != s2:
            print(f'find different solution: n = {i}, s1 = {s1}, s2 = {s2}')
            break
        else:
            print(f'passed: {i}')
        i += 1
    print(f'program end at: {i}')

compare(1000)
